#!/bin/bash

#配置权限
#chmod  -R 777 /var/www/*

#项目配置
echo "********** 进入项目目录 *************"
if [[ $USC_ROOT_PATH != "" ]]; then
	echo "USC_ROOT_PATH: $USC_ROOT_PATH"
    sed -r -i "s/#(host): (.*)/\1=$USC_ROOT_PATH/g" /var/www/h5-time/config/database.yml
fi

cd /var/www/h5-time/
echo "********** 编译 *************"
/bin/bash -l -c "bundle config mirror.https://rubygems.org https://ruby.taobao.org"
/bin/bash -l -c "bundle install"
echo "********** 创建数据库 *************"
/bin/bash -l -c "rake db:create RAILS_ENV=production"
/bin/bash -l -c "rake db:migrate RAILS_ENV=production"
/bin/bash -l -c "rake db:seed RAILS_ENV=production"
echo "********** 创建完成 *************"

echo "********** 启动 Nginx 中，请稍后 *************"
/opt/nginx/sbin/nginx -g "daemon off;"

echo "********** Good Job, 启动完成 *************"